package com.health.controller;

import com.health.pojo.Users;
import com.health.service.AttributeService;
import com.health.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

// 上传界面新增数据的Servlet
@WebServlet("/inputData")
public class InputDataServlet extends HttpServlet {
    AttributeService attributeService = new AttributeService();
    UserService userService = new UserService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        int userId = Integer.parseInt(request.getParameter("userId"));
        int attributeId = Integer.parseInt(request.getParameter("attributeId"));
        String examineDate = request.getParameter("examineDate");
        String attributeText = request.getParameter("attributeText");

        attributeService.insertData(userId, attributeId, examineDate, attributeText);

        // 获取userId回显套餐下拉信息
        List<Users> usersListByCombo = userService.searchDataByCombo(Integer.parseInt(request.getParameter("userId")));
        // 获取用户下拉框的回显下拉信息
        List<Users> usersList = userService.searchUserInformation();

        //放入请求域中
        request.setAttribute("usersListByCombo", usersListByCombo);
        request.setAttribute("usersList", usersList);


        request.getRequestDispatcher("restrictedPages/admin.jsp").forward(request, response);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
